class SuggestionsController < ApplicationController
  # GET /suggestions
  # GET /suggestions.json
  def index
    @suggestions = Suggestion.all

    respond_to do |format|
      format.json { render json: @suggestions }
    end
  end

  def show
    return unless params[:id] == 'vote'
    #TODO: Validate params
    suggestions = Suggestion.all vid: params[:vid]

    if suggestions.length == 0
      suggestion = Suggestion.create vid: params[:vid], s: params[:s], type: params[:t], v: 1
    else
      suggestion = suggestions[0]
      suggestion.v += 1
    end

    ok = suggestion.save

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: { ok: ok } }
    end
  end

end
